<template>
  <!-- 非车保险-->
  <view class="normal-login-container">

    <view class="item-wrap" style="margin-bottom: 0">
      <view class="lineBottom10 title-uni-in">
        <uni-section title="非车保险" type="line"/>
        <switch v-if="boole" color="#FFCC33" :checked="checked" @change="handleChange" style="transform:scale(0.7)"/>
      </view>
      <uni-forms ref="ruleForm" :rules="rules" :label-position="boole ? 'top' : 'left'" :model="ruleForm"
                 labelWidth="auto">

        <uni-forms-item label="其他非车险备注:">
          <uni-easyinput v-if="boole" v-model="ruleForm.otherInsuranceRemark"
                         :disabled="!checked"
                         placeholder="请输入其他非车险备注"/>
          <text v-else> {{ ruleForm.otherInsuranceRemark || '-' }}</text>
        </uni-forms-item>

        <uni-forms-item label="其他非车险保费合计:">
          <uni-easyinput v-if="boole" v-model="ruleForm.otherInsuranceSumAmount"
                         :disabled="!checked"
                         @blur="blurAmount('otherInsuranceSumAmount')"
                         placeholder="请输其他非车险保费合计"/>
          <text v-else> {{ ruleForm.otherInsuranceSumAmount || '-' }}</text>
        </uni-forms-item>


        <uni-forms-item label="附件:">
          <image-common :disabled="!boole" :up-type="2" v-model="ruleForm.attachmentUrl"/>
        </uni-forms-item>

      </uni-forms>
    </view>
  </view>
</template>

<script>
export default {
  name: 'otherpl',//非车保险
  components: {},
  props: {
    value: {
      type: Object,
      default: {},
    },
    boole: {
      type: Boolean,
      default: true,
    },
  },
  computed: {
    ruleForm: {
      get() {
        let that = this;
        const proxy = new Proxy(that.value, {
          get(target, key) {
            return Reflect.get(target, key);
          },
          set(target, key, value) {
            that.$emit("input", {...target, [key]: value});
            return true;
          },
        });
        return proxy;
      },
    },
    handleLabel() {
      return function (arr, type) {
        let name = "";
        arr.map((v) => {
          if (type == v.value) {
            name = v.label;
          }
        });
        return name;
      };
    },
  },
  data() {
    return {
      checked: false
    };
  },
  created() {
  },
  mounted() {
  },
  methods: {
    handleChange(val) {
      this.checked = val.detail.value
      if (this.checked) {
        this.value.otherOpenStatus = this.ruleForm.otherOpenStatus = 1
      } else {
        this.value.otherOpenStatus = this.ruleForm.otherOpenStatus = 0
      }
    },

    blurAmount(str) {
      if (this.ruleForm[str]) {
        let msg = /^(?:[1-9]\d*|0)(?:\.\d+)?$/;
        if (!msg.test(this.ruleForm[str])) {
          this.ruleForm[str] = "";
        } else {
          this.ruleForm[str] = this.ruleForm[str]
              .toString()
              .match(/^\d+(?:\.\d{0,2})?/)[0];
        }
      }
    },

    handleEffect() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm
            .validate()
            .then((res) => {
              resolve();
            })
            .catch((err) => {
              let key = ".flex-col" + ">>>" + "." + err[0].key;
              reject(key);
            });
      });
    },

  },
};
</script>

<style scoped lang="scss">
.title-uni-in {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
</style>


